﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections;

namespace DAL.Service.Impl
{
    public class UserCardCostServiceImpl : BaseServiceImpl, IUserCardCostService
    {
        public int getCountByUcid(int ucid)
        {
            MyQuery query = new MyQuery();
            query.setQueryString("select count(c_id) as total from joy.UserCardCost where c_ucid=@ucid");
            query.addParas("@ucid", ucid);
            Hashtable ht = (Hashtable)this.getList(query)[0];
            return Convert.ToInt32(ht["total"]);
        }

        public IList getUserTimes(int cuid)
        {
            MyQuery query = new MyQuery();
            query.setQueryString("select c_times,c_ucid from joy.UserCardCost a inner join joy.usercard b on a.c_ucid= b.uc_id WHERE uc_state=1  and  c_uid =@cuid AND getdate() between c_startTime AND c_endTime  ORDER BY c_endTime ASC");
            query.addParas("@cuid", cuid);
            return this.getList(query);
        }

        public IList currentCardList(int uid)
        { 
            MyQuery query = new MyQuery();
            query.setQueryString("select c_times,joy.getCardTimes(c_ucid) usedTimes,c_endTime  from joy.UserCardCost WHERE  c_uid =@uid AND getdate() between c_startTime AND c_endTime  ORDER BY c_endTime ASC");
            query.addParas("@uid", uid);
            return this.getList(query);
        }
    }
}
